/*
*/ 
#ifndef TGM_H
#define TGM_H

#include "obj3d.h"

#define TGM_MAGIC (('T') | ('G'<<8) | ('M'<<16) | ('1'<<24))
#define TRIS_MAGIC (('T') | ('R'<<8) | ('I'<<16) | ('S'<<24))
#define PNTS_MAGIC (('P') | ('N'<<8) | ('T'<<16) | ('S'<<24))
#define TEXV_MAGIC (('T') | ('E'<<8) | ('X'<<16) | ('V'<<24))
#define NRMS_MAGIC (('N') | ('R'<<8) | ('M'<<16) | ('S'<<24))
#define OBJX_MAGIC (('O') | ('B'<<8) | ('J'<<16) | ('X'<<24))


typedef struct 
{
    int ident;        // identifies as TGM header  (TGM1)
    int version;      // 1
    unsigned int numOBJX;    // number of objects
} TGMHeader;

typedef struct
{
    float  maxx,maxy,maxz;
    float  minx,miny,minz;
} tgmBounds;

typedef struct
{
    float  tx,ty,tz;//transform points
    float  sx,sy,sz;//scale points
    float  ttu,ttv;//transform tex
    float  stu,stv;//scale tex
} tgmXForm;

typedef struct
{
    int ID;    // rendering ID
    unsigned int numTri;     // number of tris
    unsigned int numPt;       // number of points
    unsigned int numUV;     // number of texture coords
    unsigned int numNorm;       // number of normals
    unsigned int numTrans;    // number of transforms
    unsigned int Tex;    // texture index
	tgmBounds Bounds;
	tgmXForm XForm;
} tgmOBJX;

typedef struct
{
    unsigned short  a,b,c;
    unsigned short  tv1,tv2,tv3;
//    int  na,nb,nc;
} tgmTri;

typedef struct
{
    unsigned short  x,y,z;
} tgmXYZ;

typedef struct
{
    unsigned short  u,v;
} tgmUV;

typedef struct {
	int ID;
	triangle *tris;
 	point *points;
	texcoord *tvs;
	unsigned int numPt;
	unsigned int numTri;
	unsigned int numUV;
	unsigned int Tex;
	vector scale;
	vector trans;
	vector scaletx;
	vector transtx;
	vector boundmax;
	vector boundmin;
	void* NextObj;
} tgmmodel;  

//float groundslope,shipx,shipy,shipangle;
//prototypes
int load_tgm(char *filename, tgmmodel *obj);
void draw_tgm(tgmmodel *tgm_model,uint32* textures);
void draw_tgmLOD(tgmmodel *tgm_model,uint32* textures,vector* charpos,int clipobj,int cliptri,int clipz,int texcount); 
void draw_tgm_byID(tgmmodel *tgm_model,uint32* textures,int ID,int texcount); 
void free_tgm(tgmmodel *model);

#endif
